Redux中创建Store和Reducer
新建文件夹store,并在其下新建文件index.js 和 reducer.js
index.js1
2
3
4
5
6import { createStore } from 'redux'
import reducer from './reducer'
// 创建store,并且将reducer传入
const store = createStore(reducer);
export default store;
reducer.js1
2
3
4
5
6
7
8const defaultState = {
inputVlaue: 'test',
list: [1,2,3]
}
// reducer 的返回为一个函数,函数的第一个参数是管理的数据,默认值为defaultState。第二个参数的action
export default (state = defaultState, action) => {
return state;
}
https://github.com/rexyan/simple_react/tree/Redux%E4%B8%AD%E5%88%9B%E5%BB%BAStore%E5%92%8CReducer